package com.winit.cloudlink.rabbitmq.test;


import com.winit.cloudlink.rabbitmq.mgmt.model.shovel.ShovelLink;

/**
 * @author Steven Liu
 */
public class ShovelLinkMatchers {
    public static ShovelNameMatcher name(String name) {
        return new ShovelNameMatcher(name);
    }

    public static VHostMatcher vhost(String vhost) {
        return new VHostMatcher(vhost);
    }

    public static class ShovelNameMatcher extends LikeMatcher<ShovelLink> implements ShovelLinkMatcher {
        public ShovelNameMatcher(String partten) {
            super(partten);
        }

        @Override
        protected String getValue(ShovelLink shovelLink) {
            return shovelLink.getName();
        }
    }

    public static class VHostMatcher implements ShovelLinkMatcher {

        String vhost;

        public VHostMatcher(String vhost) {

            this.vhost = vhost;
        }

        @Override
        public boolean matches(ShovelLink item) {
            return vhost.equals(item.getVhost());
        }

        @Override
        public String getNotMatchReason(ShovelLink item) {

            return String.format("Virtual host '%s' does not match expected vhost '%s'.", item.getVhost(), vhost);
        }

        @Override
        public String getMatchReason(ShovelLink item) {

            return String.format("Virtual host '%s' matches for link.", vhost);
        }
    }
}
